export default {
	getPageData(self, url, params_, successBack, errorBack) {
		let params = self.tool.cloneObj(params_);
		self.httptool.ajaxPost(url, params, function(res) {
			if(res.code == 1) {
				if(successBack) {
					successBack(res);
				} else {
					if(typeof res.data == "object" && res.data.constructor == Array) {
						self.tableData = self.formattool.trimNull(res.data, []);
					} else {
						self.tableData = self.formattool.trimNull(res.data.list, []);
						self.total = res.data.total;
					}
				}
			}
			if(self.loading) {
				self.loading = false;
			}
		}, function() {
			if(self.loading) {
				self.loading = false;
			}
		});
	},
	showDetail(self, row, title) {
		self.$refs.detail.show();
		if(row != null && row.id != 0) {
			self.id = row.id;
		} else {
			self.id = 0;
		}
		self.parentDetailData.isTabelShow = false;
	},
	getModelData(self, url, id, successBack, errorBack) {
		let params = {};
		params.id = self.id == null ? 0 : self.id;
		self.httptool.ajaxPost(url, params, function(res) {
			if(res.code == 1) {
				if(successBack) {
					successBack(res);
				} else if(res.data != null) {
					self.modelData = res.data;
				}
			} else {
				self.$message(res.msg);
			}
		});
	},
	handleSave(self, url, params, msg, successBack, errorBack) {
		self.httptool.ajaxPost(url, params, function(res) {
			if(res.code == 1) {
				self.$message({
					message: msg,
					type: 'success'
				});
				self.close();
				self.$emit('close', true);
			} else {
				self.$message(res.msg);
			}
		});
	},
	handleDelete(self, url, id, successBack, errorBack) {
		let param = {};
		param.id = id;
		self.$confirm(self.msg.delNotice, '提示', {
			confirmButtonText: '确定',
			cancelButtonText: '取消',
			type: 'warning'
		}).then(() => {
			self.httptool.ajaxPost(url, param, function(res) {
				if(res.code == 1) {
					successBack(res);
					self.$message('删除成功！');
				} else {
					self.$message(res.msg);
				}
			});
		}).catch(() => {

		});
	}
}